﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplication6.DAL.DataSetGonggaoTableAdapters;

namespace WebApplication6.manage
{
    public partial class gonggao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string action = Request["action"];

                if (action == "add")
                {
                    Label1.Text = "添加新公告";
                }
                else if (action == "edit")
                {
                    Label1.Text = "编辑公告";

                    string id = Request["id"];
                    t_gonggaoTableAdapter adapter = new t_gonggaoTableAdapter();

                    var rows = adapter.GetDataByid(Convert.ToInt32(id)).Single();


                    if (!rows.IsbiaotiNull())
                    {
                        biaoti.Text = rows.biaoti;

                    }

                    if (!rows.IsneirongNull())
                    {
                        neirong.Text = rows.neirong;

                    }

                   









                }
                else if (action == "show")
                {
                    Label1.Text = "查看公告";

                    string id = Request["id"];
                    t_gonggaoTableAdapter adapter = new t_gonggaoTableAdapter();

                    var rows = adapter.GetDataByid(Convert.ToInt32(id)).Single();


                    if (!rows.IsbiaotiNull())
                    {
                        biaoti.Text = rows.biaoti;

                    }

                    if (!rows.IsneirongNull())
                    {
                        neirong.Text = rows.neirong;

                    }

                   

                    biaoti.ReadOnly = true;
                    neirong.ReadOnly = true;
                   

                    Button1.Visible = false;

                }
                else if (action == "del")
                {
                    string id = Request["id"];

                    t_gonggaoTableAdapter adapter = new t_gonggaoTableAdapter();

                    adapter.Delete(Convert.ToInt32(id));

                    Response.Write("<script language=javascript>alert('操作成功');window.location.href='gonggaolist.aspx';</script>");

                }
                

                else
                {

                    throw new Exception("action错误" + action);
                }


            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            if (!IsValid)
            {

                return;
            }

            string action = Request["action"];

            if (action == "add")
            {
                t_gonggaoTableAdapter adapter = new t_gonggaoTableAdapter();


                adapter.Insert(biaoti.Text, neirong.Text, Convert.ToString(DateTime.Now));

                Response.Write("<script language=javascript>alert('操作成功');window.location.href='gonggaolist.aspx';</script>");
            }
            else if (action == "edit")
            {

                string id = Request["id"];

                t_gonggaoTableAdapter adapter = new t_gonggaoTableAdapter();

                var rows = adapter.GetDataByid(Convert.ToInt32(id)).Single();



                rows.biaoti = biaoti.Text;
                rows.neirong = neirong.Text;
              




                adapter.Update(rows);


                Response.Write("<script language=javascript>alert('操作成功');window.location.href='gonggaolist.aspx';</script>");

            }
            else
            {

                throw new Exception("action错误" + action);
            }

        }
    }
}
